﻿using System.Collections.Generic;

namespace _5E.Utils.DbHelper.EasySQL.Creator
{
    /// <summary>
    /// 程序说明：创建删除SQL
    /// 创建作者：ahl5esoft
    /// 创建时间：2012-04-16
    /// </summary>
    class DeleteCreator : BaseCreator, ICustomWhere
    {
        #region 变量

        private const string DELETE_SQL_FORMAT = "DELETE FROM {0} {1}";

        private string m_Where = null;

        #endregion

        #region 构造函数

        public DeleteCreator(string tableName, Dictionary<string, string> allColumns) : base(tableName, allColumns) { }

        #endregion

        #region 实例方法

        public ICustomWhere SetWhere(string where)
        {
            this.m_Where = ParseCondition.ToWhere(where, this.AllColumns);
            return this;
        }

        protected override string CreateSQL()
        {
            var sql = string.Format(DELETE_SQL_FORMAT, this.TableName, this.m_Where);
            return sql;
        }

        protected override void Reset()
        {
            this.m_Where = null;
        }

        #endregion
    }
}
